/**
 * 
 * If you have edited the file, please update
 * all the last-modified fields manually. Thanks!
 *
 * @last-modified by: Swee Zhi
 * @last-modified date: 
 * @last-modified time: 
 *
 * @author Swee Zhi
 * @date-created Sep 5, 2011    @time-created 8:30:06 PM
 *
 * @project: 
 * @module: 
 * @institution: 
 *
 */
package entity;

import java.io.Serializable;
import java.sql.Time;
import java.util.Collection;
import java.util.Date;
import java.util.TimeZone;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity(name="TripItinerary")
public class TripItineraryEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String itineraryName;
    @Temporal(value = TemporalType.DATE)
    private Date arrivalDate;
    private Time arrivalTime;
    private TimeZone arrivalTimeZone;
    @Temporal(value = TemporalType.DATE)
    private Date departureDate;
    private Time departureTime;
    private TimeZone departureTimeZone;
    private String accomodationPostalCode;
    private Integer noOfAdults;
    private Integer noOfChildren;
    
    @OneToMany(cascade={CascadeType.PERSIST}, mappedBy="tripItinerary")
    private Collection<DailyItineraryEntity> dailyItineraries;
    
//    @OneToOne(cascade={CascadeType.PERSIST})//, orphanRemoval=true)
//    private TravelInfoEntity travelInfo;
    
    
    public TripItineraryEntity() {
        
    }
    
    public void create(String itineraryName,
                       Date arrivalDate, Time arrivalTime,
                       TimeZone arrivalTimeZone,
                       Date departureDate, Time departureTime,
                       TimeZone departureTimeZone,
                       String accomodationPostalCode,
                       Integer noOfAdults, Integer noOfChildren) {
        this.setItineraryName(itineraryName);
        this.setArrivalDate(arrivalDate);
        this.setArrivalTime(arrivalTime);
        this.setArrivalTimeZone(arrivalTimeZone);
        this.setDepartureDate(departureDate);
        this.setDepartureTime(departureTime);
        this.setDepartureTimeZone(departureTimeZone);
        this.setAccomodationPostalCode(accomodationPostalCode);
        this.setNoOfAdults(noOfAdults);
        this.setNoOfChildren(noOfChildren);
    }
    
    public void updateItineraryName(String itineraryName) {
        this.setItineraryName(itineraryName);
    }
    
    public void updateTravelPeriod(Date arrivalDate, Time arrivalTime, TimeZone arrivalTimeZone, 
                                   Date departureDate, Time departureTime, TimeZone departureTimeZone) {
        this.setArrivalDate(arrivalDate);
        this.setArrivalTime(arrivalTime);
        this.setArrivalTimeZone(arrivalTimeZone);
        this.setDepartureDate(departureDate);
        this.setDepartureTime(departureTime);
        this.setDepartureTimeZone(departureTimeZone);
    }
    
    public void updateAccomodationPostalCode(String accomodationPostalCode) {
        this.setAccomodationPostalCode(accomodationPostalCode);
    }
    
    public void updateTravellerCount(Integer noOfAdults, Integer noOfChildren) {
        this.setNoOfAdults(noOfAdults);
        this.setNoOfChildren(noOfChildren);
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Collection<DailyItineraryEntity> getDailyItineraries() {
        return dailyItineraries;
    }

    public void setDailyItineraries(Collection<DailyItineraryEntity> dailyItineraries) {
        this.dailyItineraries = dailyItineraries;
    }

    public String getItineraryName() {
        return itineraryName;
    }

    public void setItineraryName(String itineraryName) {
        this.itineraryName = itineraryName;
    }

    public String getAccomodationPostalCode() {
        return accomodationPostalCode;
    }

    public void setAccomodationPostalCode(String accomodationPostalCode) {
        this.accomodationPostalCode = accomodationPostalCode;
    }

    public Integer getNoOfAdults() {
        return noOfAdults;
    }

    public void setNoOfAdults(Integer noOfAdults) {
        this.noOfAdults = noOfAdults;
    }

    public Integer getNoOfChildren() {
        return noOfChildren;
    }

    public void setNoOfChildren(Integer noOfChildren) {
        this.noOfChildren = noOfChildren;
    }

    public Date getArrivalDate() {
        return arrivalDate;
    }

    public void setArrivalDate(Date arrivalDate) {
        this.arrivalDate = arrivalDate;
    }

    public Time getArrivalTime() {
        return arrivalTime;
    }

    public void setArrivalTime(Time arrivalTime) {
        this.arrivalTime = arrivalTime;
    }

    public Date getDepartureDate() {
        return departureDate;
    }

    public void setDepartureDate(Date departureDate) {
        this.departureDate = departureDate;
    }

    public Time getDepartureTime() {
        return departureTime;
    }

    public void setDepartureTime(Time departureTime) {
        this.departureTime = departureTime;
    }

    public TimeZone getArrivalTimeZone() {
        return arrivalTimeZone;
    }

    public void setArrivalTimeZone(TimeZone arrivalTimeZone) {
        this.arrivalTimeZone = arrivalTimeZone;
    }

    public TimeZone getDepartureTimeZone() {
        return departureTimeZone;
    }

    public void setDepartureTimeZone(TimeZone departureTimeZone) {
        this.departureTimeZone = departureTimeZone;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof TripItineraryEntity)) {
            return false;
        }
        TripItineraryEntity other = (TripItineraryEntity) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "common.entity.itinerary.TripItineraryEntity[ id=" + id + " ]";
    }
    
}
